@extends('admin.common.base-master')

@section('html-head')

@endsection

@section('html-body')
    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            @if($type == 'group')
            <a href="{{route('Admin.Home.groupList')}}">活动管理</a>
            @else
            <a href="{{route('Admin.Home.goodsList')}}">商品管理</a>
            @endif
            <em> > </em>
            <a href="#">商品属性列表</a>
        </div>

        @if($type == 'group')
            @include('admin.common.activity-header')
        @endif

        <div class="filter-box clearfix">

            <div class="fr">
                @if($type == 'group')
                    <a class="addBtn" href="{{route("Admin.Home.groupGoodsSpuSet")}}?goods_id={{$goodsId}}&activity_group_id={{$activityGroupId}}">新增</a>
                @else
                    <a class="addBtn" href="{{route("Admin.Home.goodsSpuSet")}}?goods_id={{$goodsId}}">新增</a>
                @endif
            </div>
        </div>
        <div class="table-box">
            <table class="table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>商品名称</th>
                    <th>商品缩略图</th>
                    <th>商品属性名</th>
                    <th>商品价格</th>
                    @if($type == 'group')
                    <th>商品拼团价</th>
                    @endif
                    <th>商品库存</th>
                    <th>商品排序</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @if(count($goodsSpu) > 0)
                    @foreach($goodsSpu as $goods)
                        <tr id="goodsSpu_{{$goods->id}}">
                            <td>{{$goods->id}}</td>
                            <td>{{$goods->goods_name}}</td>
                            <td><a target="_blank" href="{{$goods->thumb_url}}" class="openimg"><img src="{{$goods->thumb_url}}" alt="" width="50"></a></td>
                            <td>{{$goods->spu_name}}</td>
                            <td>{{$goods->price}}</td>
                            @if($type == 'group')
                            <td>{{$goods->many_price}}</td>
                            @endif
                            <td>{{$goods->stock}}</td>
                            <td>{{$goods->sort}}</td>
                            <td>
                                @if($goods->status == 1)
                                    启用
                                @else
                                    停用
                                @endif
                            </td>
                            <td>
                                @if($type == 'group')
                                    <a class="color2" href="{{route("Admin.Home.groupGoodsSpuSet")}}?id={{$goods->id}}&goods_id={{$goodsId}}&activity_group_id={{$activityGroupId}}">编辑</a>
                                @else
                                    <a class="color2" href="{{route("Admin.Home.goodsSpuSet")}}?id={{$goods->id}}&goods_id={{$goodsId}}">编辑</a>
                                @endif
                                <span>|</span>
                                <a href="javascript:void(0);" class="del" data-id="{{$goods->id}}">删除 </a>
                            </td>
                        </tr>
                    @endforeach
                @endif
                </tbody>
            </table>
        </div>
        <div class="pagelist" style="text-align: center;">
            <?php echo $goodsSpu->appends(['goods_id' => $goodsId])->render(); ?>
        </div>
    </div>
    <script>
        $(function(){

            $(document).on("click",".del",function(){
                var id = $(this).attr("data-id");

                noty({
                    text: '你确定要删除吗?',
                    buttons: [
                        {addClass: 'btn btn-primary', text: '确定', onClick: function($noty) {
                            $noty.close();
                            $.ajax({
                                url:'{{route('Api.Admin.goods.delGoodsSpu')}}',
                                type:'post',
                                dataType:'json',
                                data:{id:id},
                                success:function(obj){
                                    if(obj.level == "success"){
                                        $("#goodsSpu_"+id).hide('slow');
                                    }else{
                                        noty({type:obj.level,text:obj.message,timeout:600});
                                    }
                                },
                                error:function(obj){
                                    console.log(obj);
                                }

                            });
                        }
                        },
                        {addClass: 'btn btn-danger', text: '取消', onClick: function($noty) {
                            $noty.close();
                        }
                        }
                    ]
                });

            });
        });
    </script>
@endsection